package dao;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import pojo.Attention;
import pojo.Page;
import pojo.User;

public interface UserDao {

	//根据用户名查找用户/登录用
	@Select(value="select * from user where user_name=#{username}")
	@Results({ @Result(property = "userId", column = "user_id",id = true), 
		@Result(property = "userName", column = "user_name"),
		@Result(property = "headSculpture", column = "head_sculpture"),
		@Result(property = "realName", column = "real_name"),
		@Result(property = "identityNumber", column = "identity_number"),
		@Result(property = "joinDate", column = "join_date")
	})
	public User selectByUserName(String  username);
	
	//查找所有用户/管理员用
	@Select(value="select * from user limit #{currentPage},#{limitNumber} ")
	@Results({ @Result(property = "userId", column = "user_id",id = true), 
		@Result(property = "userName", column = "user_name"),
		@Result(property = "headSculpture", column = "head_sculpture"),
		@Result(property = "realName", column = "real_name"),
		@Result(property = "identityNumber", column = "identity_number"),
		@Result(property = "joinDate", column = "join_date")
	})
	public List<User> selectAllUser(Page page);

	//根据用户名模糊查询
	@Select(value="select * from user where user_name like '%${text}%' limit #{page.currentPage},#{page.limitNumber}")
	@Results({ @Result(property = "userId", column = "user_id",id = true),
			@Result(property = "userName", column = "user_name"),
			@Result(property = "headSculpture", column = "head_sculpture"),
			@Result(property = "realName", column = "real_name"),
			@Result(property = "identityNumber", column = "identity_number"),
			@Result(property = "joinDate", column = "join_date")
	})
	public  List<User> selectByUserNameText(@Param("text") String text,@Param("page")Page page);

	//根据用户名模糊查询
	@Select(value="select * from user where user_name like '%${text}%' limit #{page.currentPage},#{page.limitNumber}")
	@Results({ @Result(property = "userId", column = "user_id",id = true),
			@Result(property = "userName", column = "user_name"),
			@Result(property = "headSculpture", column = "head_sculpture"),
			@Result(property = "realName", column = "real_name"),
			@Result(property = "identityNumber", column = "identity_number"),
			@Result(property = "joinDate", column = "join_date")
	})
	public  List<User> selectByUserNamePage(@Param("text") String text,@Param("page")Page page);

	//根据用户名模糊查询/
	@Select(value="select count(*) from user where user_name like '%${text}%' ")
	public int selectByUserNamePageCount(@Param("text") String text);


	//根据用户ID查询
	@Select(value="select * from user where user_id=#{userId}")
	@Results({ @Result(property = "userId", column = "user_id",id = true),
			@Result(property = "userName", column = "user_name"),
			@Result(property = "headSculpture", column = "head_sculpture"),
			@Result(property = "realName", column = "real_name"),
			@Result(property = "identityNumber", column = "identity_number"),
			@Result(property = "joinDate", column = "join_date")
	})
	public List<User> SelectByUserId(Integer userId);

	//查询关注你的用户
	@Select(value="SELECT user2_id from attention WHERE user1_id=#{userId} AND ltof=1 ")
	@Results({
			@Result(column="user2_id",property="user2Id")
	})
	public List<Integer> SelectAttentionUserId(Integer userId);

	//查询关注你的用户
	@Select(value="SELECT user1_id from attention WHERE user2_id=#{userId} AND ftol=1 ")
	@Results({
			@Result(column="user1_id",property="user1Id"),
	})
	public List<Integer> SelectAttentionUser2Id(Integer userId);

}
